﻿/**
 * Copyright (C) 2011 original author and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace NGuice.Inject.Internal.Util
{
    /// <summary>
    /// 使用windows日志系统记录NGuice日志信息的日志工具类，他将在windows日志系统中创建
    /// NGuice的事件日志，并使用具体的类名称作为日志来源名
    /// </summary>
    public class Logger
    {
        public const string LOG_NAME_NGUICE = "NGuice";

        public static EventLog GetLog(Type clazz)
        {
            EventLog log = new EventLog(LOG_NAME_NGUICE);
            if (!EventLog.SourceExists(clazz.FullName))
                EventLog.CreateEventSource(clazz.FullName, LOG_NAME_NGUICE);
            log.Source = clazz.FullName;
            return log;
        }

        public static EventLog GetLog(string name)
        {
            EventLog log = new EventLog(LOG_NAME_NGUICE);
            if (!EventLog.SourceExists(name))
                EventLog.CreateEventSource(name, LOG_NAME_NGUICE);
            log.Source = name;
            return log;
        }
    }
}
